package com.javasm.adminapi.common.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @className: MyBatisPlusConfig
 * @description:
 * @author: gfs
 * @date: 2025/9/12 16:12
 * @version: 0.1
 * @since: jdk17
 */
@Configuration
@MapperScan("com.javasm.adminapi.module.*.dao")
public class MyBatisPlusConfig {

    //注册 MyBatisPlus拦截器到Spring容器
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        //空的拦截器，需要什么插件，添加进去就可以了
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        //加载乐观锁，添加乐观锁插件，默认是没有乐观锁的
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return interceptor;
    }
}
